#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include "Mystring.h"
#include "MyCalculate.h"

/*函数的定义*/
int getMaxVal(int num1, int num2)
{
    /*函数体*/
    if (num1 > num2)
    {
        return num1;
    }
    else
    {
        return num2;
    }
}

bool isOddNum(int num1)
{
    if (num1 % 2 == 0)
    {
        return false;
    }
    else
    {
        return true;
    }
}


/*如果数组做函数参数，会弱化指针*/
int getArraySum(int *num, int length)
{

    int sum = 0;
    for (int idx = 0; idx < length; idx++)
    {
        sum += num[idx];
    }
    return sum;
}

/*void 表示没有返回值*/
void swapNum(int * num1,int * num2)
{
    int tmp = *num1;
    *num1 =  *num2;
    *num2 = tmp;
}

void StatisticsStrNum(const char* str,int *smallcnt,int *bigcnt,int *space)
{
    while(*str != '\0')
    {
        if(*str >= 'a'&&*str <= 'z')
        {
           (*smallcnt)++;
        }
        else if(*str >='A'&&*str <= 'Z')
        {
            (*bigcnt)++;
        }
        else if(*str == ' ')
        {
            (*space)++;
        }
        str++;
    }
}

void reverseStr(char * str)
{
    int length = strlen(str);
    for(int idx = 0;idx < length/2;idx++)
    {
        char tmp=str[idx];
        str[idx] = str[length-1-idx];
        str[length-1-idx] = tmp;
    }
}
int main()
{

#if 0
    /*
        函数的三要素：
            1.函数名：见名知意
            2.函数的参数：形参
                这里可以是任意的数据类型
            3.函数的返回值： 可以返回任意的数据类型  
                            void 表示没有返回值

    */

    /*函数的使用*/
    int val1 = 100;
    int val2 = 200;
    int num = getMaxVal(val1, val2);
    printf("num = %d\n", num);

    // int val3 = 100;
    // bool num2 = isOddNum(val3);
    // printf("num2 = %")

    char *str = "hello world";
    int len = MyStrlen(str);
    printf("%d\n", len);

    int nums[9] = {11, 22, 33, 44, 55, 66, 77, 88, 99};
    int length = sizeof(nums) / sizeof(nums[0]);
    int sum = getArraySum(nums, length);
    printf("%d\n", sum);

#endif

#if 0
    int val1 = 100;
    int val2 = 200;

    swapNum(&val1, &val2);

    printf("val1 = %d,val2 = %d\n",val1,val2);

    return 0;
#endif

#if 1
    /*多文件编译*/
    char str1[30] ="sqsasdad";
    char str2[30] = "swffaf";

    int ret = MyStrcmp(str1,str2);
    printf("%d\n",ret);

    Mystrcat(str1,str2);
    printf("str1 = %s\n",str1);

    Mystrcpy(str1,str2);
    printf("str1 = %s\n",str1);
#endif

#if 0
    int num1 = 10;
    int num2 = 5;

    int sum = My_Add(num1,num2);
    printf("%d\n",sum);
#endif

#if 0
    /*传入参数和传出参数
    传入参数:不可以被修改的参数教传入参数。如果是整数，就不加地址。如果是字符串，就加const
    传出参数:一定会被修改的参数叫传出参数：如果是整数，一定加地址。如果是字符串，不加const
    */
    char *buffer= "hEllo woRld   ";
    /*调用函数的参数叫实参*/
    int smallcnt =0;
    int bigcnt = 0;
    int space = 0;
    StatisticsStrNum(buffer,&smallcnt,&bigcnt,&space);
    printf("小写字母有\t%d个\n",smallcnt);
    printf("大写字母有\t%d个\n",bigcnt);
    printf("空格有\t\t%d个\n",space);

#endif

#if 0
    char str[] = "hello world";
    reverseStr(str);
    printf("%s\n",str);
#endif

return 0;
}